﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Yammu.Core.MediaManagement
{
    public class MediaDir : MediaItemBase, IMediaDir
    {
        protected List<IMediaDir> _childDirs = new List<IMediaDir>();
        protected List<IMediaFile>  _childFiles = new List<IMediaFile>();

        public MediaDir()
        {
            
        }

        #region Overrides of MediaItemBase
        
        public override bool IsDirectory
        {
            get { return true; }
        }

        #endregion

        #region Implementation of IMediaDir

        public IList<IMediaDir> Directories
        {
            get { return _childDirs.AsReadOnly(); }
        }

        public IList<IMediaFile> Files
        {
            get { return _childFiles.AsReadOnly();  }
        }

        public virtual void AddItem(IMediaItem mediaItem)
        {
            
            if( mediaItem.IsDirectory)
            {
                if( _childDirs.Exists( (item)=> mediaItem.Equals(item)))
                            _childDirs.Add(mediaItem as IMediaDir);
            }
            else
            {
                if (_childFiles.Exists((item) => mediaItem.Equals(item)))
                    _childFiles.Add(mediaItem as IMediaFile);
            }
        }

        #endregion
    }
}
